package com.yixun.qfbao.filters;

import com.alibaba.fastjson.JSONObject;
import org.apache.log4j.Logger;

import javax.servlet.*;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.io.OutputStream;
import java.io.PrintWriter;


public class UploadIpFilter implements Filter {
    private static Logger log = Logger.getLogger(UploadIpFilter.class);
    @Override
    public void init(FilterConfig filterConfig) throws ServletException {

    }

    @Override
    public void doFilter(ServletRequest request, ServletResponse response, FilterChain chain) throws IOException, ServletException {
        /*
        String ip = ((HttpServletRequest)request).getRemoteAddr();
        if(!"127.0.0.1".equals(ip)){
            JSONObject res = new JSONObject();
            response.setContentType("application/json; charset=utf-8");
            response.setCharacterEncoding("UTF-8");
            res.put("result","0");
            res.put("errorMsg","非法ip");
            PrintWriter out = response.getWriter();
            out.append(res.toJSONString());
            out.flush();
        }else{
            chain.doFilter(request, response);
        }
        */
        chain.doFilter(request, response);
    }

    @Override
    public void destroy() {

    }
}
